home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 13, No. 03 (1992-03)(MindCraft Publishing)(Side A).zip / Nibble Volume 13, No. 03 (1992-03)(MindCraft Publishing)(Side A).po / KEY.QWIK.S.txt < prev    next >
Text File  |  1996-12-24  |  13KB  |  453 lines

  1. ; Key Qwik
  2. ; by Jerry Edens
  3. ;
  4. ; Copyright (C) 1992 by
  5. ; MindCraft Publishing Corp.
  6. ; Lincoln, MA 01773
  7. ;
  8. ; Orca/M v4.1 Assembler
  9. ;
  10. Global      data
  11. Zero        Gequ  $00
  12. One         Gequ  $01
  13. LOC0        Gequ  $02
  14. LOC1        Gequ  $03
  15. LOC2        Gequ  $04
  16. LOC3        Gequ  $05
  17. Math_Reg1   Gequ  $06
  18. Math_Reg2   Gequ  $07
  19. Math_Reg3   Gequ  $08
  20. Math_Reg4   Gequ  $09
  21. Ch          Gequ  $24        ; Horzontal position of cursor <40 col>
  22. basl        Gequ  $28        ; LOB, address of line cursor is on.
  23. bash        Gequ  $29        ; HOB ^^^^^^^^
  24. Inst_len    Gequ  $2F        ; Instruction length.
  25. Prompt      Gequ  $33        ; Prompt character storage
  26. A1L         Gequ  $3C        ; A1 start address for move
  27. A1H         Gequ  $3D
  28. A2L         Gequ  $3E        ; A2 end address for move
  29. A2H         Gequ  $3F
  30. A4L         Gequ  $42        ; A4 destnation address for move.
  31. A4H         Gequ  $43
  32. TempY       Gequ  $58
  33. Return      Gequ  $8D
  34. I_Buf       Gequ  $0200      ; Input buffer for getln
  35. Ourch       Gequ  $057B      ; Cusor position horizontal in <80 col>
  36. Wrm_Dos     Gequ  $BE00      ; Warm start entry point into dos.
  37. Dos_Cmd     Gequ  $BE03      ; Executes the command in the input buffer.
  38. Exter_Cmd   Gequ  $BE07      ; Jmp EXTRNCMD hook
  39. Err_Out     Gequ  $BE09      ; Executes the BI error command handler.
  40. State       Gequ  $BE42      ; >0 if deferred, else immediate mode.
  41. Vpath1      Gequ  $BE6C      ; Primary pathname buffer addrress
  42. Go_sys      Gequ  $BE70      ; execute dos command
  43. S_Close     Gequ  $BEDD      ; system level
  44. Get_buf     Gequ  $BEF5      ; Get buffer # of pages in ACC.
  45. Himem       Gequ  $BEFB      ; High memory.
  46. Level       Gequ  $BF94
  47. Mach_id     Gequ  $BF98
  48. rd80col     Gequ  $C01F
  49. txtpage1    Gequ  $C054
  50. txtpage2    Gequ  $C055
  51. Eightyon    Gequ  $C300
  52. Insds2      Gequ  $F88E      ; Monitor disasmbler
  53. Home        Gequ  $FC58      ; Clear the entire screen
  54. Rdkey       Gequ  $FD0C      ; Get the input key.
  55. PrByte      Gequ  $FDDA      ; Print the byte in the acc.
  56. Cout        Gequ  $FDED      ; Output a character through the ksw
  57. Move        Gequ  $FE2C      ; Move a block of memory
  58. Clreol      Gequ  $FC9C      ; Clear to end of line.
  59.             end
  60.  
  61. ;
  62. ;
  63. ; Relocate : This routine will relocate the program.
  64. ;
  65.  
  66. relocate    start
  67.             using txt_cmd
  68.             using commands
  69.             using rest_data
  70.  
  71.             msb   on
  72.             lda   #Zero
  73.             sta   level
  74.             sta   s_close+1
  75.             lda   #$cc
  76.             cld
  77.             jsr   go_sys
  78.  
  79.             lda   mach_id
  80.             lsr   a
  81.             lsr   a
  82.             bcc   go_on
  83.             jsr   eightyon
  84. go_on       jsr   home
  85.  
  86.             ldx   #Zero       ; Prints out the
  87. loop_copy   lda   copyright,x ; copyright mesg.
  88.             beq   copy_done
  89.             jsr   cout
  90.             inx
  91.             bne   loop_copy
  92.  
  93. copy_done   lda   exter_cmd+1
  94.             sta   exter_prior+1
  95.             lda   exter_cmd
  96.             sta   exter_prior
  97.  
  98.             lda   #pages      ; Set pages needed.
  99.             jsr   get_buf     ; Have basic.system
  100.             bcc   good        ; reserve the buffer
  101.             jmp   err_out     ; display any error
  102. good        sta   himem       ; new high mem
  103.             sta   exter_cmd+1 ; Rest external command
  104.             sec               ; Prepare for subtraction.
  105.             sbc   prg_strt+1  ; start - destination.
  106.             sta   math_reg1   ; Store the results.
  107.             lda   prg_strt+1  ;
  108.             sta   a1h
  109.             lda   #Zero
  110.             sta   exter_cmd
  111.             sta   a1l
  112.  
  113. loop        ldy   #Zero       ; Zero index register.
  114.             lda   (a1l),y     ; Get the instruction. (opcode)
  115.             beq   update      ; If zero then update pc.
  116.             jsr   insds2      ; Disasmble the instruction.
  117.             ldy   inst_len    ; Get the instruction length.
  118.             cpy   #$02        ; three byte instruction?
  119.             bne   wrong_len   ; If not the inst. doesn't have
  120.             lda   (a1l),y     ; a two byte address.
  121.             jsr   new_address ; present add + new highmem
  122.             sta   (a1l),y
  123. wrong_len   iny
  124.             tya               ; Continue untill complete
  125.             jsr   pc_update
  126.             jmp   loop
  127.  
  128. update      lda   #$01        ; Add one to the pc.
  129.             jsr   pc_update
  130. update_1    ldy   #$01
  131.             lda   (a1l),y
  132.             beq   branch_1
  133.             jsr   new_address
  134.             sta   (a1l),y
  135.             lda   #$02
  136.             jsr   pc_update
  137.             jmp   update_1
  138.  
  139. branch_1    ldy   #$01        ;
  140. branch_2    lda   commands,y  ; update the address table.
  141.             beq   out         ;
  142.             clc
  143.             adc   math_reg1
  144.             sta   commands,y
  145.             iny
  146.             iny
  147.             bne   branch_2
  148.  
  149. out         ldx   #Zero       ;
  150.             lda   prg_strt+1  ; Once addresses are updated,
  151.             stx   a1l         ; do the move.
  152.             sta   a1h         ;
  153.             ldx   #<end
  154.             lda   #>end
  155.             stx   a2l
  156.             sta   a2h
  157.             lda   #Zero
  158.             sta   a4l
  159.             lda   himem
  160.             sta   a4h
  161.             ldy   #Zero
  162.             jmp   move
  163.  
  164. new_address cmp   prg_strt+1  ;
  165.             bcc   not_ok      ; See if address is within the
  166.             cmp   ending+1    ; start & stop points
  167.             beq   ok          ; If not then leave it alone.
  168.             bcs   not_ok
  169. ok          clc
  170.             adc   math_reg1   ; If yes then update then
  171. not_ok      rts               ; address.
  172.  
  173. pc_update   clc               ;
  174.             adc   a1l         ; Update the pc by one.
  175.             sta   a1l         ;
  176.             lda   a1h         ;
  177.             adc   #Zero
  178.             sta   a1h
  179.             rts
  180.             end
  181.  
  182. ;
  183. ;
  184. ; Rest_Data : This is the data area for the relocate routine
  185. ;
  186.  
  187. Rest_Data   data
  188.             using txt_cmd
  189.  
  190. prg_strt    dc    a'new_cmd'
  191. ending      dc    a'end'
  192. buf_a       ds    1
  193. amount      ds    1
  194. pages       equ   $03
  195.  
  196. copyright   dc    c'Key Qwik by Jerry Edens',h'8d'
  197.             dc    c'Copyright (C) 1992, MindCraft Publ. Corp.',h'8d 8d 00'
  198.             end
  199.  
  200. ;
  201. ;
  202. ; New_Cmd : This is the paraser for the input commands.
  203. ;
  204. ; Inputs : The command line pointed to by VPATH1 holds
  205. ;          the command not recognized by the BI.
  206. ;
  207. ; Outputs : None
  208. ;
  209.  
  210.             align 256
  211. New_Cmd     start
  212.             using txt_cmd
  213.             using commands
  214.             using rest_data
  215.  
  216.             cld              ; Used by BI...
  217.             lda   state      ; Is a basic program running.
  218.             and   #$FF
  219.             beq   lb1        ; If sate flag a zero no prog.
  220. back        jmp   not_found
  221.  
  222. lb1         lda   prompt     ; Check to see if in the monitor
  223.             cmp   #'*'       ; if yes don't bother with
  224.             beq   back
  225.  
  226.             lda   vpath1
  227.             sta   loc0
  228.             lda   vpath1+1
  229.             sta   loc1
  230.  
  231.             ldy   #one       ; Get the partial command,
  232. loop_new    lda   (loc0),y   ; Move it into the buffer 'Path',
  233.             beq   out
  234.             ora   #$80       ; set the high bit. (for B.I.)
  235.             sta   path-1,y
  236.             iny
  237.             bne   loop_new
  238.  
  239. ;
  240. ;  Check the first letter of the command to see if it is
  241. ;  a posible valid command.
  242. ;
  243.  
  244. out         ldx   #Zero       ; Zero index regs
  245.             ldy   #Zero
  246. loop_1      lda   commands,x  ; set up the pointer
  247.             sta   loc2        ; to the command table
  248.             inx
  249.             lda   commands,x
  250.             bne   over        ; When zero all commands
  251.             jmp   not_found   ; have been checked
  252. over        sta   loc3
  253.             inx
  254.             lda   path,y      ; Get first letter of command
  255.             cmp   (loc2),y    ; Is it same as first letter
  256.             beq   so_far_good
  257.             bcs   loop_1
  258.             jmp   not_found
  259.  
  260. ; O.K. the first letter matched one of the commands
  261. ; now, check the rest of the command.
  262.  
  263. so_far_good iny
  264.             lda   path,y
  265.             cmp   #$8d
  266.             beq   done
  267.             cmp   (loc2),y
  268.             beq   so_far_good
  269.  
  270.             lda   commands,x  ; letter didn't match
  271.             sta   loc2        ; keelp checking
  272.             inx
  273.             lda   commands,x
  274.             sta   loc3
  275.             inx
  276.             ldy   #Zero
  277.             lda   path,y
  278.             cmp   (loc2),y
  279.             beq   so_far_good
  280.             jmp   not_found
  281. done        ldy   #$01
  282.             jsr   first_col   ; Move the cursor to column #1
  283. ;
  284. ; Put the command on the screen as well as in the I_Buf...
  285. ;
  286.             ldy   #Zero       ;
  287. loop_5      lda   (loc2),y    ; When command is found put it in
  288.             beq   In_buff     ; buffer @$200  and display it
  289.             sta   I_buf,y     ; on the screen
  290.             jsr   cout        ;
  291.             iny
  292.             bne   loop_5
  293. ;
  294. ; Take additional inputs for the command.... i.e.
  295. ; filename, pathname, slot, drive, etc...
  296. ;
  297. In_buff     tya               ; length of string is in Y reg.
  298.             tax               ; transfer it to the X reg.
  299. load_key    jsr   rdkey       ;
  300.             cmp   #$8D        ; return we are complete
  301.             beq   complete    ;
  302.             cmp   #$88        ; left arrow move the cursor
  303.             beq   left        ; left and delete previous character.
  304.             cmp   #$9b        ; character an esc key start all
  305.             beq   esc_key     ; starts you all over
  306.             cmp   #$FF
  307.             beq   left
  308.             cmp   #$95        ; right arrow ignore it.
  309.             beq   load_key    ;
  310.             sta   I_buf,x     ; all other chacters in the buffer.
  311.             jsr   cout        ; Syntax is a user responsabilty.
  312.             inx
  313.             bne   load_key
  314. ;
  315. ; The command has been found and has been placed in the
  316. ; input buffer at $200... Now give control to B.I...
  317. ;
  318. complete    sta   I_buf,x     ;
  319.             jsr   Dos_cmd     ; Call the BI
  320.             bcc   rts         ; let it do the
  321.             rts               ; work.
  322. rts         jmp   wrm_dos
  323. ;
  324. ; The command was not found. Give control to
  325. ; the previous External command.
  326. ;
  327. not_found   lda   exter_prior+1
  328.             sta   exter_jmp+2
  329.             lda   exter_prior
  330.             sta   exter_jmp+1
  331.             sec
  332. exter_jmp   jmp   $FFFF
  333.  
  334. left        bit   rd80col     ;
  335.             bpl   fourty      ; Move the cursor
  336.             dec   ourch       ; to the left and
  337.             lda   ourch       ; delete the
  338.             lsr   a           ; character.
  339.             tay
  340.             beq   over_2
  341.             php
  342.             sei
  343.             lda   #$a0
  344.             pha
  345.             bit   txtpage2
  346.             bcc   not_2
  347.             lda   txtpage1
  348. not_2       pla
  349.             sta   (basl),y
  350.             sta   txtpage1
  351.             plp
  352.             bne   over_2
  353.  
  354. fourty      lda   #$a0
  355.             dec   ch
  356.             ldy   ch
  357.             beq   over_3
  358. over_2      lda   #$a0
  359.             sta   (basl),y
  360.             dex
  361. over_3      jmp   load_key
  362.  
  363. esc_key     clc
  364.             lda   #Zero
  365.             sta   ch
  366.             sta   ourch
  367.             jsr   clreol
  368.             jmp   wrm_dos
  369.  
  370. first_col   sty   tempy       ;
  371.             ldy   #$01        ; Move cursor to col #1
  372.             bit   rd80col     ;
  373.             bpl   four
  374.             sty   ourch
  375.             bne   eighty
  376. four        sty   ch
  377. eighty      ldy   tempy
  378.             rts
  379.  
  380. re_set      ldy   #17
  381. re_loop     lda   #Zero
  382.             sta   I_buf,y
  383.             dey
  384.             bpl   re_loop
  385.             rts
  386.             dc    h'00 00'
  387.             end
  388.  
  389. ;
  390. ;
  391. ; Commands : This is the address table for the txt
  392. ;            which goes into the buffer @$200.
  393. ;
  394.  
  395. Commands    data
  396.             using txt_cmd
  397.  
  398.             dc    a'bye'
  399.             dc    a'bload'
  400.             dc    a'brun'
  401.             dc    a'bsave'
  402.             dc    a'catalog'
  403.             dc    a'close'
  404.             dc    a'create'
  405.             dc    a'delete'
  406.             dc    a'exec'
  407.             dc    a'in'
  408.             dc    a'load'
  409.             dc    a'lock'
  410.             dc    a'pr'
  411.             dc    a'prefix'
  412.             dc    a'rename'
  413.             dc    a'run'
  414.             dc    a'save'
  415.             dc    a'unlock'
  416.             dc    a'verify'
  417.             dc    h'00 00'
  418. exter_prior ds    2
  419.             end
  420.  
  421. ;
  422. ;
  423. ; Txt_Cmd : This is the text data for the commands.
  424. ;           This is the information which is put into
  425. ;           the buffer @$200. For use by the BI.
  426. ;
  427.  
  428.             msb   on
  429. Txt_Cmd     data
  430.  
  431. Bye         dc    c'BYE',h'00'
  432. Bload       dc    c'BLOAD ',h'00'
  433. Brun        dc    c'BRUN ',h'00'
  434. Bsave       dc    c'BSAVE ',h'00'
  435. Catalog     dc    c'CATALOG ',h'00'
  436. Close       dc    c'CLOSE ',h'00'
  437. Create      dc    c'CREATE ',h'00'
  438. Delete      dc    c'DELETE ',h'00'
  439. Exec        dc    c'EXEC ',h'00'
  440. In          dc    c'IN#',h'00'
  441. Load        dc    c'LOAD ',h'00'
  442. Lock        dc    c'LOCK ',h'00'
  443. Pr          dc    c'PR#',h'00'
  444. Prefix      dc    c'PREFIX ',h'00'
  445. Rename      dc    c'RENAME ',h'00'
  446. Run         dc    c'RUN ',h'00'
  447. Save        dc    c'SAVE ',h'00'
  448. Unlock      dc    c'UNLOCK ',h'00'
  449. Verify      dc    c'VERIFY ',h'00'
  450. Path        ds    64
  451. end         ds    1
  452.             end
  453.